package com.foreveross.proxyip.application.impl.offer;

import java.util.List;

import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.annotate.JsonUnwrapped;

import com.foreveross.proxyip.application.offer.IProxyIPService;
import com.foreveross.proxyip.application.offer.bean.ProxyIpDTO;

/**
 * 装饰者
 * @author lyq
 */
@Path("/proxyipService")
public class ProxyIpResource  implements IProxyIPService  {

	IProxyIPService proxyIPService;
	
	public ProxyIpResource(IProxyIPService proxyIPService){
		this.proxyIPService = proxyIPService;
	}
//	@POST
//	@Consumes(MediaType.APPLICATION_JSON)
//	@Produces(MediaType.APPLICATION_JSON)
//	@Path("/getProxyIp")
//	@Override
//	public ProxyIpDTO getProxyIp(String auth) throws Exception {
//		return proxyIPService.getProxyIp(auth);
//	}

	
	@GET
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/getProxyIp/{auth}/{clientIp}")
	@Override
	public ProxyIpDTO getProxyIp(@PathParam("auth")String auth,@PathParam("clientIp")String clientIp) throws Exception {
		return proxyIPService.getProxyIp(auth,clientIp);
	}

//	@Override
//	public List<ProxyIpDTO> getProxyIps(int size, String auth) throws Exception {
//		return proxyIPService.getProxyIps(size, auth);
//	}
	
	@GET
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/getProxyIps/{size}/{auth}/{clientIp}")
	@Override
	public List<ProxyIpDTO> getProxyIps(@PathParam("size")int size,@PathParam("auth") String auth, @PathParam("clientIp")String clientIp)
			throws Exception {
		return proxyIPService.getProxyIps(size, auth, clientIp);
	}

//	@Override
//	public ProxyIpDTO getChannelProxyIp(String channel, String auth)
//			throws Exception {
//		return proxyIPService.getChannelProxyIp(channel, auth);
//	}
	@GET
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/getChannelProxyIp/{channel}/{auth}/{clientIp}")
	@Override
	public ProxyIpDTO getChannelProxyIp(@PathParam("channel")String channel,@PathParam("auth") String auth,
			@PathParam("clientIp") String clientIp) throws Exception {
		return proxyIPService.getChannelProxyIp(channel, auth, clientIp);
	}

//	@Override
//	public List<ProxyIpDTO> getChannelProxyIps(String channel, int size,
//			String auth) throws Exception {
//		// TODO Auto-generated method stub
//		return null;
//	}
	@GET
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/getChannelProxyIps/{channel}/{size}/{auth}/{clientIp}")
	@Override
	public List<ProxyIpDTO> getChannelProxyIps(@PathParam("channel")String channel, @PathParam("size")int size,
			@PathParam("auth")String auth, @PathParam("clientIp")String clientIp) throws Exception {
		return proxyIPService.getChannelProxyIps(channel, size, auth,clientIp);
	}
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	@Path("/recycle/{auth}")
	@Override
	public boolean recycle(ProxyIpDTO proxyIp,@PathParam("auth") String auth) throws Exception {
		if(proxyIp==null){
			throw new Exception("ipBean 为空");
		}
		if(StringUtils.isBlank(proxyIp.getChannelId())){
			throw new Exception("channId  为空,请检查！！！！");
		}
		return proxyIPService.recycle(proxyIp, auth);
	}

	
}
